package ldh.im.fxbase.util;

import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import ldh.im.fxbase.cell.ObjectTableCellFactory;

public class TableViewUtil {

    public static void alignment(Pos alignment, TableView tableView, String... excludeTableColumnNames) {
        ObservableList<TableColumn> tableColumns = tableView.getColumns();
        for (TableColumn tableColumn : tableColumns) {
            boolean isExclude = false;
            for (String excludeTableColumnName : excludeTableColumnNames) {
                if (tableColumn.getText().equals(excludeTableColumnName)) {
                    isExclude = true;
                    break;
                }
            }
            if (!isExclude) {
                tableColumn.setCellFactory(new ObjectTableCellFactory(e -> e, alignment));
            }
        }
    }

    public static void alignment(Pos alignment, TableColumn... tableColumns) {
        for (TableColumn tableColumn : tableColumns) {
            tableColumn.setCellFactory(new ObjectTableCellFactory(e -> e, alignment));
        }
    }

    public static void alignment(Pos alignment, TableView tableView) {
        ObservableList<TableColumn> tableColumns = tableView.getColumns();
        for (TableColumn tableColumn : tableColumns) {
            tableColumn.setCellFactory(new ObjectTableCellFactory(e -> e, alignment));
        }
    }
}
